package logic

import (
	"context"
	"everyone/B/rpc_B/model/mysql"

	"everyone/B/rpc_B/everyone"
	"everyone/B/rpc_B/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewOrderListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderListLogic {
	return &OrderListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *OrderListLogic) OrderList(in *everyone.OrderListRequest) (*everyone.OrderListResponse, error) {
	// todo: add your logic here and delete this line
	o := mysql.Order{}
	order, err := o.Find(in.OrderStatue, in.Page, in.PageSize)
	if err != nil {
		logx.Error("订单查询失败")
	}
	var orders []*everyone.OrderItem
	for _, s := range order {
		orders = append(orders, &everyone.OrderItem{
			GoodsId:     s.GoodsId,
			GoodsTitle:  s.GoodsTitle,
			SynOrder:    s.SynOrder,
			OrderStatue: s.OrderStatue,
			OrderType:   s.OrderType,
		})
	}
	return &everyone.OrderListResponse{
		OrderList: orders,
	}, nil
}
